const {
  categories,
  fzf_shouc,
} = require('../../http/api');
Page({
  data: {
    list: [],
    itemId: [],
    itemOOD: [],
    baran: [], // 轮播图
    content: [], // 富文本,
    show: false,
    value: '1',
    title: 1,
    id: [],
    backup: [],
    isShow: false,
    shouc:[],
    numms:0,
  },
  share(e) {
    console.log("点击了");
    var that = this;
    var sh = that.data.isShow;
    that.setData({
      isShow: !sh
    })
  },
  cancel(e) {
    console.log("取消");
    var that = this;
    var sh = that.data.isShow;
    that.setData({
      isShow:!sh
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.itemId = options.id;
    // console.log(this.data.itemId);
    console.log(this.data.itemId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    categories(this.data.itemId).then((res) => {
      // console.log(res.basicInfo.id);
      this.data.baran = res.pics
      this.data.list = res.basicInfo
      this.setData({
        baran: this.data.baran,
        list: this.data.list,
        shouc:res.basicInfo,
        content: res.content
      })
      console.log(res.category.type);
      if(res.category.type == 0){
        this.setData({
          numms:1,
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏2  
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  showPopup() {
    this.setData({
      show: true
    })
    console.log("1111");
  },
  onClose() {
    this.setData({
      show: false
    })
  },
   //购物车
   fzf_gwcs(){
    wx.reLaunch({
      url: '/pages/shopping/shopping',
    })
  },  

  // 收藏
  fzf_shouc(){
    this.setData({
      numms : this.data.numms+1,
    })
    var id = this.data.shouc.id;
    var type = 0;
    console.log(type);
    console.log(id);
    if(this.data.numms%2 == 0){
      fzf_shouc(id,type);
    }
    console.log(this.data.shouc.type);
  },
  onClickJR(e) {
    this.data.id = e.currentTarget.dataset.list.id,
      wx.reLaunch({
        url: "/pages/shopping/shopping?data=" + [this.data.id, this.data.title]
      })
  },
  onChange(value) {
    this.setData({
      title: value.detail,
    })
    // console.log(value.detail);
  }
})